package com.wr.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author 王瑞
 * @description: 自定义DubboFilter
 * @date 2020/4/16  11:21
 */
@Activate(group = {CommonConstants.PROVIDER})
public class TransportIPFilter implements Filter {
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        //获取RpcContext
        RpcContext context = RpcContext.getContext();
        //从RpcContext中获取调用者的host
        String host = context.getRemoteHost();
        //将调用端获取的host放入RpcContext中
        context.setAttachment("remoteHost",host);
        return invoker.invoke(invocation);
    }
}
